var express = require('express');
var router = express.Router();

var jwt = require('jsonwebtoken');

router.get('/', function(req, res, next) {

  console.log(req.query)
  
  if (req.query.username == 'admin' && req.query.pw == '123'){

    var token = jwt.sign({ username:"admin"}, "ttt123", 
                        {expiresIn:"1d",
                        algorithm:"HS256",})
    
    res.json({
      code: 1,
      msg: "登录成功",
      token,

  })
  } else {
    res.json({
      code: 0,
      msg: '登录失败',
    })

  }

  
}
)


router.post('/', function(req,res,next){
  console.log(req.body)
  res.json({
    code: 1,
    msg: '注册成功',
  })
})





module.exports = router;
